package cn.silver.framework.satoken.enums;

import cn.silver.framework.core.model.DictModel;
import cn.silver.framework.core.utils.StreamUtils;
import cn.silver.framework.core.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;

@Getter
@AllArgsConstructor
public enum DeviceTypeEnums {

    PC("pc", "桌面设备", Boolean.TRUE),

    APP("app", "移动端设备", Boolean.FALSE),

    XCX("xcx", "微信小程序", Boolean.FALSE),

    SOCIAL("social", "社交媒体", Boolean.FALSE),
    TEMP("temp", "临时登录认证", Boolean.FALSE),
    ;

    private final String code;
    private final String name;
    private final Boolean built;

    public static DeviceTypeEnums getDeviceType(String str) {
        for (DeviceTypeEnums value : values()) {
            if (StringUtils.contains(str, value.getCode())) {
                return value;
            }
        }
        throw new RuntimeException("'DeviceType' not found By " + str);
    }

    public static List<DictModel> getModels() {
        return StreamUtils.toList(Arrays.asList(values()), item -> new DictModel(item.name, item.code));
    }
}
